﻿using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class CharatorSlot : Slot
{
    public Equipment.EquitmentType equitmentType;
    public Weapon.WeaponType weaponType;

    public override void OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData)
    {
       
        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }
        Debug.Log("helloword");
        //PickItem上有装备
            //该物品槽有装备
                //PickItem装备适合放在该物品槽中       交换
                //PickItem装备不适合放在该物品槽中      不做处理
            //该物品槽无装备
                //PickItem装备适合放在该物品槽中       放入
                //PickItem装备不适合放在该物品槽中      不做处理
        //PickItem上无装备
            //该物品槽有装备   
                //将该物品槽内物品放入到PickItem       
            //该物品槽无装备   不做处理

        if (KnapsackManager.GetInstance.isPickGood)
        {
            if (this.transform.childCount != 0)
            {
                if (IsRightSlot(KnapsackManager.GetInstance.GetPickGoodUI.good))
                {
                    this.transform.GetChild(0).GetComponent<GoodUI>().Exchange(KnapsackManager.GetInstance.GetPickGoodUI);

                    StorageSlot.slot.StoreGood(KnapsackManager.GetInstance.GetPickGoodUI.good,KnapsackManager.GetInstance.GetPickGoodUI.amount);
                    KnapsackManager.GetInstance.GetPickGoodUI.SetLocalPosition(new Vector3(-420, 2, 0));
                    KnapsackManager.GetInstance.isPickGood = false;
                }
                else
                {
                    //不做处理
                }
            }
            else
            {
                if (IsRightSlot(KnapsackManager.GetInstance.GetPickGoodUI.good))
                {
                    StoreGood(KnapsackManager.GetInstance.GetPickGoodUI.good, KnapsackManager.GetInstance.GetPickGoodUI.amount);
                    KnapsackManager.GetInstance.GetPickGoodUI.SetLocalPosition(new Vector3(-420, 2, 0));
                    KnapsackManager.GetInstance.isPickGood = false;
                }
                else
                {
                    //不做处理
                }
            }
        }
        else
        {
            if (this.transform.childCount != 0)
            {
                Destroy(this.transform.GetChild(0).gameObject);

                KnapsackManager.GetInstance.GetPickGoodUI.SetGood(this.transform.GetChild(0).GetComponent<GoodUI>().good, this.transform.GetChild(0).GetComponent<GoodUI>().amount);
                KnapsackManager.GetInstance.isPickGood = true;

                StorageSlot.slot = this;
            }
            else
            {
                //不做处理
            }
        }
    }


    private bool IsRightSlot(KnapsackGood KG)
    {
        if (KG is Equipment && ((Equipment)KG).equitmentType==this.equitmentType
          ||KG is Weapon &&((Weapon)KG).weaponType==this.weaponType)
        {
            return true;
        }

        return false;
    }
}
